{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用逻辑回归方法解决音乐推荐问题\n",
    "\n",
    "# 对测试数据进行处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import pickle as pk\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import math\n",
    "import scipy.io as sio\n",
    "import scipy.sparse as ss\n",
    "import copy\n",
    "%matplotlib inline\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_path = '../Data/'  # 文件路径\n",
    "model_path = '../model/' # 模型路径"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(model_path+'data_all_test.pkl', 'rb') as fr:\n",
    "    data_all_test = pk.load(fr)\n",
    "fr.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>city</th>\n",
       "      <th>bd</th>\n",
       "      <th>registered_via</th>\n",
       "      <th>registration_init_time</th>\n",
       "      <th>expiration_date</th>\n",
       "      <th>song_length</th>\n",
       "      <th>language</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>2.556790e+06</td>\n",
       "      <td>2.556790e+06</td>\n",
       "      <td>2.556790e+06</td>\n",
       "      <td>2.556790e+06</td>\n",
       "      <td>2.556790e+06</td>\n",
       "      <td>2.556790e+06</td>\n",
       "      <td>2.556765e+06</td>\n",
       "      <td>2.556748e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.278394e+06</td>\n",
       "      <td>7.421128e+00</td>\n",
       "      <td>1.740118e+01</td>\n",
       "      <td>6.786635e+00</td>\n",
       "      <td>2.012931e+07</td>\n",
       "      <td>2.017177e+07</td>\n",
       "      <td>2.438435e+05</td>\n",
       "      <td>1.996903e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>7.380818e+05</td>\n",
       "      <td>6.669526e+00</td>\n",
       "      <td>2.221715e+01</td>\n",
       "      <td>2.266561e+00</td>\n",
       "      <td>3.099333e+04</td>\n",
       "      <td>3.564131e+03</td>\n",
       "      <td>7.335050e+04</td>\n",
       "      <td>2.161928e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>-4.300000e+01</td>\n",
       "      <td>3.000000e+00</td>\n",
       "      <td>2.004033e+07</td>\n",
       "      <td>2.005061e+07</td>\n",
       "      <td>1.486000e+03</td>\n",
       "      <td>-1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>6.391972e+05</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>4.000000e+00</td>\n",
       "      <td>2.011072e+07</td>\n",
       "      <td>2.017091e+07</td>\n",
       "      <td>2.132520e+05</td>\n",
       "      <td>3.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.278394e+06</td>\n",
       "      <td>5.000000e+00</td>\n",
       "      <td>2.100000e+01</td>\n",
       "      <td>7.000000e+00</td>\n",
       "      <td>2.013112e+07</td>\n",
       "      <td>2.017093e+07</td>\n",
       "      <td>2.392810e+05</td>\n",
       "      <td>3.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.917592e+06</td>\n",
       "      <td>1.300000e+01</td>\n",
       "      <td>2.900000e+01</td>\n",
       "      <td>9.000000e+00</td>\n",
       "      <td>2.015112e+07</td>\n",
       "      <td>2.017101e+07</td>\n",
       "      <td>2.704190e+05</td>\n",
       "      <td>5.200000e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>2.556789e+06</td>\n",
       "      <td>2.200000e+01</td>\n",
       "      <td>1.051000e+03</td>\n",
       "      <td>1.600000e+01</td>\n",
       "      <td>2.017023e+07</td>\n",
       "      <td>2.020102e+07</td>\n",
       "      <td>7.356917e+06</td>\n",
       "      <td>5.900000e+01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 id          city            bd  registered_via  \\\n",
       "count  2.556790e+06  2.556790e+06  2.556790e+06    2.556790e+06   \n",
       "mean   1.278394e+06  7.421128e+00  1.740118e+01    6.786635e+00   \n",
       "std    7.380818e+05  6.669526e+00  2.221715e+01    2.266561e+00   \n",
       "min    0.000000e+00  1.000000e+00 -4.300000e+01    3.000000e+00   \n",
       "25%    6.391972e+05  1.000000e+00  0.000000e+00    4.000000e+00   \n",
       "50%    1.278394e+06  5.000000e+00  2.100000e+01    7.000000e+00   \n",
       "75%    1.917592e+06  1.300000e+01  2.900000e+01    9.000000e+00   \n",
       "max    2.556789e+06  2.200000e+01  1.051000e+03    1.600000e+01   \n",
       "\n",
       "       registration_init_time  expiration_date   song_length      language  \n",
       "count            2.556790e+06     2.556790e+06  2.556765e+06  2.556748e+06  \n",
       "mean             2.012931e+07     2.017177e+07  2.438435e+05  1.996903e+01  \n",
       "std              3.099333e+04     3.564131e+03  7.335050e+04  2.161928e+01  \n",
       "min              2.004033e+07     2.005061e+07  1.486000e+03 -1.000000e+00  \n",
       "25%              2.011072e+07     2.017091e+07  2.132520e+05  3.000000e+00  \n",
       "50%              2.013112e+07     2.017093e+07  2.392810e+05  3.000000e+00  \n",
       "75%              2.015112e+07     2.017101e+07  2.704190e+05  5.200000e+01  \n",
       "max              2.017023e+07     2.020102e+07  7.356917e+06  5.900000e+01  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7fcf02a79da0>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAD4CAYAAAAJmJb0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAO+UlEQVR4nO3dcayddX3H8fdn9FKrVQG5YNeCp1sblaECuWE43ULEOVAnZBGDWbRxJM0Strm5Rar+YfaHBrNlbGabprNuNRqVMBeIsE1kkoUlsF0UUayOG3qFSoVrpmiq2LJ990dP6wUO7Tk9z+2598f7lZyc5/k9v+f5ff/p5/76O+d5TqoKSVKbfm7SBUiSlo4hL0kNM+QlqWGGvCQ1zJCXpIatmnQBi5166qnV6/UmXYYkrSh33XXX96pqetCxZRXyvV6P2dnZSZchSStKkm8/3TGXaySpYUOHfJKPJ3kkydcXtZ2S5JYk9/XfT+63J8mHk8wluSfJeUtRvCTpyEaZyf8DcPGT2rYBt1bVZuDW/j7AJcDm/msr8JHxypQkHYuhQ76q/h34nyc1Xwrs7G/vBC5b1P6JOugO4KQk68YtVp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9jVOB7026CGmAF1XV9KADyyrkpeUsyWxVzUy6DmkULtdIUsMMeUlqmCEvDW/7pAuQRuWavCQ1zJm8JDXMkJekhhny0pMk6SX5+lH6XJjk88erJulYGfKS1DBDXhpsVZKdSe5Jcn2SZye5OMk3k9wO/NakC5SGYchLg70Y2F5VLwd+CLwL+DvgN4FfBV44wdqkoRny0mAPVtV/9Lc/CcwAu6vqvv4P1X9ycqVJwzPkpcGefAPJ8we0ScueIS8NdmaSV/a33wp8EdiY5BcXtUnLniEvDbYL2JLkHuAU4FpgK3BT/4NXH4mtFcHHGkhSw5zJS1LDDHlJapghL0kNM+QlqWGGvCQ1zJCXpIYZ8pLUsP8HdPiH6Eso0SMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 观察测试集的年龄分布\n",
    "# data_all_test.head()\n",
    "data_all_test[data_all_test.bd<100].bd.plot.box()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 年龄数据离散化\n",
    "def get_bd_section(bd, bd_mean_section):\n",
    "    if bd < 9 and bd > 100: # 所有的异常值都设为平均值所在的区间\n",
    "        bd = bd_mean_section\n",
    "    elif bd < 18:\n",
    "        bd = 1\n",
    "    elif bd < 26:\n",
    "        bd = 2\n",
    "    elif bd < 36:\n",
    "        bd = 3\n",
    "    elif bd < 46:\n",
    "        bd = 4\n",
    "    elif bd < 56:\n",
    "        bd = 5\n",
    "    elif bd < 66:\n",
    "        bd = 6\n",
    "    else:\n",
    "        bd = 7\n",
    "    return bd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>msno</th>\n",
       "      <th>song_id</th>\n",
       "      <th>source_system_tab</th>\n",
       "      <th>source_screen_name</th>\n",
       "      <th>source_type</th>\n",
       "      <th>city</th>\n",
       "      <th>bd</th>\n",
       "      <th>gender</th>\n",
       "      <th>registered_via</th>\n",
       "      <th>registration_init_time</th>\n",
       "      <th>expiration_date</th>\n",
       "      <th>song_length</th>\n",
       "      <th>genre_ids</th>\n",
       "      <th>artist_name</th>\n",
       "      <th>composer</th>\n",
       "      <th>lyricist</th>\n",
       "      <th>language</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>0</td>\n",
       "      <td>V8ruy7SGk7tDm3zA51DPpn6qutt+vmKMBKa21dp54uM=</td>\n",
       "      <td>WmHKgKMlp1lQMecNdNvDMkvIycZYHnFwDT72I5sIssc=</td>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>20160219</td>\n",
       "      <td>20170918</td>\n",
       "      <td>224130.0</td>\n",
       "      <td>458</td>\n",
       "      <td>梁文音 (Rachel Liang)</td>\n",
       "      <td>Qi Zheng Zhang</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.0</td>\n",
       "      <td>愛其實很殘忍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>1</td>\n",
       "      <td>V8ruy7SGk7tDm3zA51DPpn6qutt+vmKMBKa21dp54uM=</td>\n",
       "      <td>y/rsZ9DC7FwK5F2PK2D5mj+aOBUJAjuu3dZ14NgE0vM=</td>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>20160219</td>\n",
       "      <td>20170918</td>\n",
       "      <td>320470.0</td>\n",
       "      <td>465</td>\n",
       "      <td>林俊傑 (JJ Lin)</td>\n",
       "      <td>林俊傑</td>\n",
       "      <td>孫燕姿/易家揚</td>\n",
       "      <td>3.0</td>\n",
       "      <td>她說</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>2</td>\n",
       "      <td>/uQAlrAkaczV+nWCd2sPF2ekvXPRipV7q0l+gbLuxjw=</td>\n",
       "      <td>8eZLFOdGVdXBSqoAv5nsLigeH2BvKXzTQYtUM53I0k4=</td>\n",
       "      <td>discover</td>\n",
       "      <td>NaN</td>\n",
       "      <td>song-based-playlist</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4</td>\n",
       "      <td>20161117</td>\n",
       "      <td>20161124</td>\n",
       "      <td>315899.0</td>\n",
       "      <td>2022</td>\n",
       "      <td>Yu Takahashi (高橋優)</td>\n",
       "      <td>Yu Takahashi</td>\n",
       "      <td>Yu Takahashi</td>\n",
       "      <td>17.0</td>\n",
       "      <td>subarashiki nichijo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>3</td>\n",
       "      <td>1a6oo/iXKatxQx4eS9zTVD+KlSVaAFbTIqVvwLC1Y0k=</td>\n",
       "      <td>ztCf8thYsS4YN3GcIL/bvoxLm/T5mYBVKOO4C9NiVfQ=</td>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>20070725</td>\n",
       "      <td>20170430</td>\n",
       "      <td>285210.0</td>\n",
       "      <td>465</td>\n",
       "      <td>U2</td>\n",
       "      <td>The Edge| Adam Clayton| Larry Mullen| Jr.</td>\n",
       "      <td>NaN</td>\n",
       "      <td>52.0</td>\n",
       "      <td>Hold Me| Thrill Me| Kiss Me| Kill Me</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>4</td>\n",
       "      <td>1a6oo/iXKatxQx4eS9zTVD+KlSVaAFbTIqVvwLC1Y0k=</td>\n",
       "      <td>MKVMpslKcQhMaFEgcEQhEfi5+RZhMYlU3eRDpySrH8Y=</td>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>20070725</td>\n",
       "      <td>20170430</td>\n",
       "      <td>197590.0</td>\n",
       "      <td>873</td>\n",
       "      <td>Yoga Mr Sound</td>\n",
       "      <td>Neuromancer</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>Om Yoga</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        id                                          msno  \\\n",
       "76126    0  V8ruy7SGk7tDm3zA51DPpn6qutt+vmKMBKa21dp54uM=   \n",
       "790668   1  V8ruy7SGk7tDm3zA51DPpn6qutt+vmKMBKa21dp54uM=   \n",
       "52111    2  /uQAlrAkaczV+nWCd2sPF2ekvXPRipV7q0l+gbLuxjw=   \n",
       "159296   3  1a6oo/iXKatxQx4eS9zTVD+KlSVaAFbTIqVvwLC1Y0k=   \n",
       "160750   4  1a6oo/iXKatxQx4eS9zTVD+KlSVaAFbTIqVvwLC1Y0k=   \n",
       "\n",
       "                                             song_id source_system_tab  \\\n",
       "76126   WmHKgKMlp1lQMecNdNvDMkvIycZYHnFwDT72I5sIssc=        my library   \n",
       "790668  y/rsZ9DC7FwK5F2PK2D5mj+aOBUJAjuu3dZ14NgE0vM=        my library   \n",
       "52111   8eZLFOdGVdXBSqoAv5nsLigeH2BvKXzTQYtUM53I0k4=          discover   \n",
       "159296  ztCf8thYsS4YN3GcIL/bvoxLm/T5mYBVKOO4C9NiVfQ=             radio   \n",
       "160750  MKVMpslKcQhMaFEgcEQhEfi5+RZhMYlU3eRDpySrH8Y=             radio   \n",
       "\n",
       "         source_screen_name          source_type  city  bd gender  \\\n",
       "76126   Local playlist more        local-library     1   1    NaN   \n",
       "790668  Local playlist more        local-library     1   1    NaN   \n",
       "52111                   NaN  song-based-playlist     1   1    NaN   \n",
       "159296                Radio                radio     3   3   male   \n",
       "160750                Radio                radio     3   3   male   \n",
       "\n",
       "        registered_via  registration_init_time  expiration_date  song_length  \\\n",
       "76126                7                20160219         20170918     224130.0   \n",
       "790668               7                20160219         20170918     320470.0   \n",
       "52111                4                20161117         20161124     315899.0   \n",
       "159296               9                20070725         20170430     285210.0   \n",
       "160750               9                20070725         20170430     197590.0   \n",
       "\n",
       "       genre_ids         artist_name  \\\n",
       "76126        458  梁文音 (Rachel Liang)   \n",
       "790668       465        林俊傑 (JJ Lin)   \n",
       "52111       2022  Yu Takahashi (高橋優)   \n",
       "159296       465                  U2   \n",
       "160750       873       Yoga Mr Sound   \n",
       "\n",
       "                                         composer      lyricist  language  \\\n",
       "76126                              Qi Zheng Zhang           NaN       3.0   \n",
       "790668                                        林俊傑       孫燕姿/易家揚       3.0   \n",
       "52111                                Yu Takahashi  Yu Takahashi      17.0   \n",
       "159296  The Edge| Adam Clayton| Larry Mullen| Jr.           NaN      52.0   \n",
       "160750                                Neuromancer           NaN      -1.0   \n",
       "\n",
       "                                        name  \n",
       "76126                                 愛其實很殘忍  \n",
       "790668                                    她說  \n",
       "52111                    subarashiki nichijo  \n",
       "159296  Hold Me| Thrill Me| Kiss Me| Kill Me  \n",
       "160750                               Om Yoga  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将 bd 特征中的离群值都设置为中位数\n",
    "bd_mean_section = 3\n",
    "data_all_test['bd'] = data_all_test.bd.apply(lambda x: get_bd_section(x, bd_mean_section))\n",
    "data_all_test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    1093505\n",
       "3     643151\n",
       "2     550406\n",
       "4     184761\n",
       "5      65296\n",
       "6      14301\n",
       "7       5370\n",
       "Name: bd, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test.bd.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 歌曲长度离散化，单位 ms\n",
    "def get_song_length_section(song_length):\n",
    "    if song_length < 1000*60*5:\n",
    "        return 1\n",
    "    elif song_length < 1000*60*10:\n",
    "        return 2\n",
    "    elif song_length < 1000*60*20:\n",
    "        return 3\n",
    "    elif song_length < 1000*60*30:\n",
    "        return 4\n",
    "    elif song_length < 1000*60*40:\n",
    "        return 5\n",
    "    elif song_length < 1000*60*50:\n",
    "        return 6\n",
    "    elif song_length < 1000*60*60:\n",
    "        return 7\n",
    "    else: \n",
    "        return 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>msno</th>\n",
       "      <th>song_id</th>\n",
       "      <th>source_system_tab</th>\n",
       "      <th>source_screen_name</th>\n",
       "      <th>source_type</th>\n",
       "      <th>city</th>\n",
       "      <th>bd</th>\n",
       "      <th>gender</th>\n",
       "      <th>registered_via</th>\n",
       "      <th>registration_init_time</th>\n",
       "      <th>expiration_date</th>\n",
       "      <th>song_length</th>\n",
       "      <th>genre_ids</th>\n",
       "      <th>artist_name</th>\n",
       "      <th>composer</th>\n",
       "      <th>lyricist</th>\n",
       "      <th>language</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>0</td>\n",
       "      <td>V8ruy7SGk7tDm3zA51DPpn6qutt+vmKMBKa21dp54uM=</td>\n",
       "      <td>WmHKgKMlp1lQMecNdNvDMkvIycZYHnFwDT72I5sIssc=</td>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>20160219</td>\n",
       "      <td>20170918</td>\n",
       "      <td>1</td>\n",
       "      <td>458</td>\n",
       "      <td>梁文音 (Rachel Liang)</td>\n",
       "      <td>Qi Zheng Zhang</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.0</td>\n",
       "      <td>愛其實很殘忍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>1</td>\n",
       "      <td>V8ruy7SGk7tDm3zA51DPpn6qutt+vmKMBKa21dp54uM=</td>\n",
       "      <td>y/rsZ9DC7FwK5F2PK2D5mj+aOBUJAjuu3dZ14NgE0vM=</td>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>20160219</td>\n",
       "      <td>20170918</td>\n",
       "      <td>2</td>\n",
       "      <td>465</td>\n",
       "      <td>林俊傑 (JJ Lin)</td>\n",
       "      <td>林俊傑</td>\n",
       "      <td>孫燕姿/易家揚</td>\n",
       "      <td>3.0</td>\n",
       "      <td>她說</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>2</td>\n",
       "      <td>/uQAlrAkaczV+nWCd2sPF2ekvXPRipV7q0l+gbLuxjw=</td>\n",
       "      <td>8eZLFOdGVdXBSqoAv5nsLigeH2BvKXzTQYtUM53I0k4=</td>\n",
       "      <td>discover</td>\n",
       "      <td>NaN</td>\n",
       "      <td>song-based-playlist</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4</td>\n",
       "      <td>20161117</td>\n",
       "      <td>20161124</td>\n",
       "      <td>2</td>\n",
       "      <td>2022</td>\n",
       "      <td>Yu Takahashi (高橋優)</td>\n",
       "      <td>Yu Takahashi</td>\n",
       "      <td>Yu Takahashi</td>\n",
       "      <td>17.0</td>\n",
       "      <td>subarashiki nichijo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>3</td>\n",
       "      <td>1a6oo/iXKatxQx4eS9zTVD+KlSVaAFbTIqVvwLC1Y0k=</td>\n",
       "      <td>ztCf8thYsS4YN3GcIL/bvoxLm/T5mYBVKOO4C9NiVfQ=</td>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>20070725</td>\n",
       "      <td>20170430</td>\n",
       "      <td>1</td>\n",
       "      <td>465</td>\n",
       "      <td>U2</td>\n",
       "      <td>The Edge| Adam Clayton| Larry Mullen| Jr.</td>\n",
       "      <td>NaN</td>\n",
       "      <td>52.0</td>\n",
       "      <td>Hold Me| Thrill Me| Kiss Me| Kill Me</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>4</td>\n",
       "      <td>1a6oo/iXKatxQx4eS9zTVD+KlSVaAFbTIqVvwLC1Y0k=</td>\n",
       "      <td>MKVMpslKcQhMaFEgcEQhEfi5+RZhMYlU3eRDpySrH8Y=</td>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>20070725</td>\n",
       "      <td>20170430</td>\n",
       "      <td>1</td>\n",
       "      <td>873</td>\n",
       "      <td>Yoga Mr Sound</td>\n",
       "      <td>Neuromancer</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>Om Yoga</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        id                                          msno  \\\n",
       "76126    0  V8ruy7SGk7tDm3zA51DPpn6qutt+vmKMBKa21dp54uM=   \n",
       "790668   1  V8ruy7SGk7tDm3zA51DPpn6qutt+vmKMBKa21dp54uM=   \n",
       "52111    2  /uQAlrAkaczV+nWCd2sPF2ekvXPRipV7q0l+gbLuxjw=   \n",
       "159296   3  1a6oo/iXKatxQx4eS9zTVD+KlSVaAFbTIqVvwLC1Y0k=   \n",
       "160750   4  1a6oo/iXKatxQx4eS9zTVD+KlSVaAFbTIqVvwLC1Y0k=   \n",
       "\n",
       "                                             song_id source_system_tab  \\\n",
       "76126   WmHKgKMlp1lQMecNdNvDMkvIycZYHnFwDT72I5sIssc=        my library   \n",
       "790668  y/rsZ9DC7FwK5F2PK2D5mj+aOBUJAjuu3dZ14NgE0vM=        my library   \n",
       "52111   8eZLFOdGVdXBSqoAv5nsLigeH2BvKXzTQYtUM53I0k4=          discover   \n",
       "159296  ztCf8thYsS4YN3GcIL/bvoxLm/T5mYBVKOO4C9NiVfQ=             radio   \n",
       "160750  MKVMpslKcQhMaFEgcEQhEfi5+RZhMYlU3eRDpySrH8Y=             radio   \n",
       "\n",
       "         source_screen_name          source_type  city  bd gender  \\\n",
       "76126   Local playlist more        local-library     1   1    NaN   \n",
       "790668  Local playlist more        local-library     1   1    NaN   \n",
       "52111                   NaN  song-based-playlist     1   1    NaN   \n",
       "159296                Radio                radio     3   3   male   \n",
       "160750                Radio                radio     3   3   male   \n",
       "\n",
       "        registered_via  registration_init_time  expiration_date  song_length  \\\n",
       "76126                7                20160219         20170918            1   \n",
       "790668               7                20160219         20170918            2   \n",
       "52111                4                20161117         20161124            2   \n",
       "159296               9                20070725         20170430            1   \n",
       "160750               9                20070725         20170430            1   \n",
       "\n",
       "       genre_ids         artist_name  \\\n",
       "76126        458  梁文音 (Rachel Liang)   \n",
       "790668       465        林俊傑 (JJ Lin)   \n",
       "52111       2022  Yu Takahashi (高橋優)   \n",
       "159296       465                  U2   \n",
       "160750       873       Yoga Mr Sound   \n",
       "\n",
       "                                         composer      lyricist  language  \\\n",
       "76126                              Qi Zheng Zhang           NaN       3.0   \n",
       "790668                                        林俊傑       孫燕姿/易家揚       3.0   \n",
       "52111                                Yu Takahashi  Yu Takahashi      17.0   \n",
       "159296  The Edge| Adam Clayton| Larry Mullen| Jr.           NaN      52.0   \n",
       "160750                                Neuromancer           NaN      -1.0   \n",
       "\n",
       "                                        name  \n",
       "76126                                 愛其實很殘忍  \n",
       "790668                                    她說  \n",
       "52111                    subarashiki nichijo  \n",
       "159296  Hold Me| Thrill Me| Kiss Me| Kill Me  \n",
       "160750                               Om Yoga  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test['song_length'] = data_all_test.song_length.fillna(0)\n",
    "data_all_test['song_length'] = data_all_test.apply(lambda x: get_song_length_section(x.song_length), axis=1)\n",
    "data_all_test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def add_ids_2_set(genre_ids, id_set):\n",
    "    genre_ids = str(genre_ids)\n",
    "    id_arr = genre_ids.split('|')\n",
    "    for item in id_arr:\n",
    "        id_set.add(item)\n",
    "    return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "id_set = set()\n",
    "temp = data_all_test.genre_ids.apply(lambda ids: add_ids_2_set(ids,id_set))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "163\n"
     ]
    }
   ],
   "source": [
    "genre_id_list = list(id_set)\n",
    "genre_id_len = len(genre_id_list)\n",
    "print(len(genre_id_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 建立 genre_id 索引\n",
    "genre_id_index = dict()\n",
    "for i,genre_id in enumerate(genre_id_list):\n",
    "    genre_id_index[genre_id] = i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2556790"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_genre_id_matrix(data_all_train,genre_id_index):    \n",
    "    genre_id_matrix = ss.dok_matrix((data_all_test.shape[0], genre_id_len), dtype='uint8')\n",
    "    for df_index in range(data_all_test.shape[0]):\n",
    "        line = data_all_test.iloc[df_index, :]\n",
    "        for item in str(line.genre_ids).split('|'):\n",
    "             id_index = genre_id_index[item]\n",
    "             genre_id_matrix[df_index,id_index] = 1\n",
    "    return genre_id_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "genre_id_matrix = get_genre_id_matrix(data_all_test,genre_id_index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['genre_id_0',\n",
       " 'genre_id_1',\n",
       " 'genre_id_2',\n",
       " 'genre_id_3',\n",
       " 'genre_id_4',\n",
       " 'genre_id_5',\n",
       " 'genre_id_6',\n",
       " 'genre_id_7',\n",
       " 'genre_id_8',\n",
       " 'genre_id_9',\n",
       " 'genre_id_10',\n",
       " 'genre_id_11',\n",
       " 'genre_id_12',\n",
       " 'genre_id_13',\n",
       " 'genre_id_14',\n",
       " 'genre_id_15',\n",
       " 'genre_id_16',\n",
       " 'genre_id_17',\n",
       " 'genre_id_18',\n",
       " 'genre_id_19',\n",
       " 'genre_id_20',\n",
       " 'genre_id_21',\n",
       " 'genre_id_22',\n",
       " 'genre_id_23',\n",
       " 'genre_id_24',\n",
       " 'genre_id_25',\n",
       " 'genre_id_26',\n",
       " 'genre_id_27',\n",
       " 'genre_id_28',\n",
       " 'genre_id_29',\n",
       " 'genre_id_30',\n",
       " 'genre_id_31',\n",
       " 'genre_id_32',\n",
       " 'genre_id_33',\n",
       " 'genre_id_34',\n",
       " 'genre_id_35',\n",
       " 'genre_id_36',\n",
       " 'genre_id_37',\n",
       " 'genre_id_38',\n",
       " 'genre_id_39',\n",
       " 'genre_id_40',\n",
       " 'genre_id_41',\n",
       " 'genre_id_42',\n",
       " 'genre_id_43',\n",
       " 'genre_id_44',\n",
       " 'genre_id_45',\n",
       " 'genre_id_46',\n",
       " 'genre_id_47',\n",
       " 'genre_id_48',\n",
       " 'genre_id_49',\n",
       " 'genre_id_50',\n",
       " 'genre_id_51',\n",
       " 'genre_id_52',\n",
       " 'genre_id_53',\n",
       " 'genre_id_54',\n",
       " 'genre_id_55',\n",
       " 'genre_id_56',\n",
       " 'genre_id_57',\n",
       " 'genre_id_58',\n",
       " 'genre_id_59',\n",
       " 'genre_id_60',\n",
       " 'genre_id_61',\n",
       " 'genre_id_62',\n",
       " 'genre_id_63',\n",
       " 'genre_id_64',\n",
       " 'genre_id_65',\n",
       " 'genre_id_66',\n",
       " 'genre_id_67',\n",
       " 'genre_id_68',\n",
       " 'genre_id_69',\n",
       " 'genre_id_70',\n",
       " 'genre_id_71',\n",
       " 'genre_id_72',\n",
       " 'genre_id_73',\n",
       " 'genre_id_74',\n",
       " 'genre_id_75',\n",
       " 'genre_id_76',\n",
       " 'genre_id_77',\n",
       " 'genre_id_78',\n",
       " 'genre_id_79',\n",
       " 'genre_id_80',\n",
       " 'genre_id_81',\n",
       " 'genre_id_82',\n",
       " 'genre_id_83',\n",
       " 'genre_id_84',\n",
       " 'genre_id_85',\n",
       " 'genre_id_86',\n",
       " 'genre_id_87',\n",
       " 'genre_id_88',\n",
       " 'genre_id_89',\n",
       " 'genre_id_90',\n",
       " 'genre_id_91',\n",
       " 'genre_id_92',\n",
       " 'genre_id_93',\n",
       " 'genre_id_94',\n",
       " 'genre_id_95',\n",
       " 'genre_id_96',\n",
       " 'genre_id_97',\n",
       " 'genre_id_98',\n",
       " 'genre_id_99',\n",
       " 'genre_id_100',\n",
       " 'genre_id_101',\n",
       " 'genre_id_102',\n",
       " 'genre_id_103',\n",
       " 'genre_id_104',\n",
       " 'genre_id_105',\n",
       " 'genre_id_106',\n",
       " 'genre_id_107',\n",
       " 'genre_id_108',\n",
       " 'genre_id_109',\n",
       " 'genre_id_110',\n",
       " 'genre_id_111',\n",
       " 'genre_id_112',\n",
       " 'genre_id_113',\n",
       " 'genre_id_114',\n",
       " 'genre_id_115',\n",
       " 'genre_id_116',\n",
       " 'genre_id_117',\n",
       " 'genre_id_118',\n",
       " 'genre_id_119',\n",
       " 'genre_id_120',\n",
       " 'genre_id_121',\n",
       " 'genre_id_122',\n",
       " 'genre_id_123',\n",
       " 'genre_id_124',\n",
       " 'genre_id_125',\n",
       " 'genre_id_126',\n",
       " 'genre_id_127',\n",
       " 'genre_id_128',\n",
       " 'genre_id_129',\n",
       " 'genre_id_130',\n",
       " 'genre_id_131',\n",
       " 'genre_id_132',\n",
       " 'genre_id_133',\n",
       " 'genre_id_134',\n",
       " 'genre_id_135',\n",
       " 'genre_id_136',\n",
       " 'genre_id_137',\n",
       " 'genre_id_138',\n",
       " 'genre_id_139',\n",
       " 'genre_id_140',\n",
       " 'genre_id_141',\n",
       " 'genre_id_142',\n",
       " 'genre_id_143',\n",
       " 'genre_id_144',\n",
       " 'genre_id_145',\n",
       " 'genre_id_146',\n",
       " 'genre_id_147',\n",
       " 'genre_id_148',\n",
       " 'genre_id_149',\n",
       " 'genre_id_150',\n",
       " 'genre_id_151',\n",
       " 'genre_id_152',\n",
       " 'genre_id_153',\n",
       " 'genre_id_154',\n",
       " 'genre_id_155',\n",
       " 'genre_id_156',\n",
       " 'genre_id_157',\n",
       " 'genre_id_158',\n",
       " 'genre_id_159',\n",
       " 'genre_id_160',\n",
       " 'genre_id_161',\n",
       " 'genre_id_162']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成 genre_id 在 dataframe 中的列名\n",
    "genre_id_columns = list()\n",
    "for i in range(genre_id_len):\n",
    "    genre_id_columns.append('genre_id_'+str(i))\n",
    "genre_id_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2556790, 163)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>genre_id_0</th>\n",
       "      <th>genre_id_1</th>\n",
       "      <th>genre_id_2</th>\n",
       "      <th>genre_id_3</th>\n",
       "      <th>genre_id_4</th>\n",
       "      <th>genre_id_5</th>\n",
       "      <th>genre_id_6</th>\n",
       "      <th>genre_id_7</th>\n",
       "      <th>genre_id_8</th>\n",
       "      <th>genre_id_9</th>\n",
       "      <th>...</th>\n",
       "      <th>genre_id_153</th>\n",
       "      <th>genre_id_154</th>\n",
       "      <th>genre_id_155</th>\n",
       "      <th>genre_id_156</th>\n",
       "      <th>genre_id_157</th>\n",
       "      <th>genre_id_158</th>\n",
       "      <th>genre_id_159</th>\n",
       "      <th>genre_id_160</th>\n",
       "      <th>genre_id_161</th>\n",
       "      <th>genre_id_162</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 163 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        genre_id_0  genre_id_1  genre_id_2  genre_id_3  genre_id_4  \\\n",
       "76126            0           0           0           0           0   \n",
       "790668           0           0           0           0           0   \n",
       "52111            0           0           0           0           0   \n",
       "159296           0           0           0           0           0   \n",
       "160750           0           0           0           0           0   \n",
       "\n",
       "        genre_id_5  genre_id_6  genre_id_7  genre_id_8  genre_id_9  ...  \\\n",
       "76126            0           0           0           0           0  ...   \n",
       "790668           0           1           0           0           0  ...   \n",
       "52111            0           0           0           0           0  ...   \n",
       "159296           0           1           0           0           0  ...   \n",
       "160750           0           0           0           0           0  ...   \n",
       "\n",
       "        genre_id_153  genre_id_154  genre_id_155  genre_id_156  genre_id_157  \\\n",
       "76126              0             0             0             0             0   \n",
       "790668             0             0             0             0             0   \n",
       "52111              0             0             0             0             0   \n",
       "159296             0             0             0             0             0   \n",
       "160750             0             0             0             0             0   \n",
       "\n",
       "        genre_id_158  genre_id_159  genre_id_160  genre_id_161  genre_id_162  \n",
       "76126              0             0             0             0             0  \n",
       "790668             0             0             0             0             0  \n",
       "52111              0             0             0             0             0  \n",
       "159296             0             0             0             0             0  \n",
       "160750             0             0             0             0             0  \n",
       "\n",
       "[5 rows x 163 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "genre_id_df = pd.DataFrame(genre_id_matrix.todense(), columns = genre_id_columns, index = data_all_test.index, dtype='uint8')  \n",
    "print(genre_id_df.shape)\n",
    "genre_id_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "genre_ids memory usage: 456.956987 Mb\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(2556790, 163)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "genre_id_mem = genre_id_df.memory_usage().sum()/(1024**2)\n",
    "print('genre_ids memory usage: %f Mb' % genre_id_mem)\n",
    "genre_id_df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# with open(model_path + 'data_all_train_v1.pkl','wb') as fw:\n",
    "#     pk.dump(data_all_train,fw)\n",
    "# fw.close()\n",
    "# 文件太大，存储报错(更改数据类型后，文件变为了原来的三分之一)\n",
    "with open(model_path + 'genre_id_test_df.pkl','wb') as fw:\n",
    "    pk.dump(genre_id_df,fw)\n",
    "fw.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test = data_all_test.drop(['genre_ids'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test = data_all_test.drop(['artist_name','composer','lyricist','name'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 保存 id 和 target_list \n",
    "msno_list = data_all_test.msno\n",
    "song_id_list = data_all_test.song_id\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将 册数数据的 msno 特征存储到硬盘 \n",
    "with open(model_path + 'msno_list_test.pkl','wb') as fw:\n",
    "    pk.dump(msno_list,fw)\n",
    "fw.close()\n",
    "# 将 训练数据的 song_id 特征存储到硬盘 \n",
    "with open(model_path + 'song_id_list_test.pkl','wb') as fw:\n",
    "    pk.dump(song_id_list,fw)\n",
    "fw.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test = data_all_test.drop(['msno','song_id'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 填充source_system_tab的缺失值\n",
    "data_all_test['source_system_tab']=data_all_test.source_system_tab.fillna('tab_NaN')\n",
    "# 填充 source_screen_name 的缺失值\n",
    "data_all_test['source_screen_name']=data_all_test.source_screen_name.fillna('screen_name_NaN')\n",
    "# 填充 source_type 的缺失值\n",
    "data_all_test['source_type']=data_all_test.source_type.fillna('source_type_NaN')\n",
    "# 填充 city 的缺失值\n",
    "data_all_test['city']=data_all_test.city.fillna('city_NaN')\n",
    "# 填充 gender 的缺失值\n",
    "data_all_test['gender']=data_all_test.gender.fillna('gender_NaN')\n",
    "# 填充 registered_via 的缺失值\n",
    "data_all_test['registered_via']=data_all_test.registered_via.fillna('via_NaN')\n",
    "# 填充 language 的缺失值\n",
    "data_all_test['language']=data_all_test.language.fillna('language_NaN')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# registration_init_time  expiration_date   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test['registration_init_time'] = data_all_test.registration_init_time.astype('str')\n",
    "data_all_test['expiration_date'] = data_all_test.expiration_date.astype('str')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test['registration_init_time_format'] = pd.to_datetime(data_all_test.registration_init_time, format='%Y%m%d')\n",
    "data_all_test['expiration_date_format'] = pd.to_datetime(data_all_test.expiration_date, format='%Y%m%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test['registration_interval_time'] = data_all_test.expiration_date_format - data_all_test.registration_init_time_format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test = data_all_test.drop(['registration_init_time','expiration_date','registration_init_time_format','expiration_date_format'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test['registration_interval_time_days'] = data_all_test.registration_interval_time.astype('timedelta64[D]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7fcf029665c0>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD5CAYAAADLL+UrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAATX0lEQVR4nO3df7DddX3n8edLQMEfJSBXxg1o4pqdFduK7l1g1+4OQjf8aht2Vipuq9EyzXSW3VZ3dzTuuIJad3E6s3RoC7NpoURrBfxVWKDFDMJYbflxgRBEtEkhSiaMhAaorsoWee8f53PhEO6Pc5P7I/B5PmbunO/3/f18v9/P9yR5nU8+53vuSVUhSerDi5a6A5KkxWPoS1JHDH1J6oihL0kdMfQlqSMHLnUHZnLEEUfUihUrlrobkvS8cscddzxSVWNTbduvQ3/FihVMTEwsdTck6XklyXem2+b0jiR1xNCXpI4Y+pLUEUNfkjpi6EtSR/bru3ek/VGS59T8xYV6vnCkL83BVIE/U13a3xj6ktQRQ1+SOmLoS1JHDH1J6shIoZ9ke5J7kmxOMtFqhyfZlGRrezys1ZPkoiTbkmxJ8pah46xt7bcmWbswlyRJms5cRvpvq6pjq2q8ra8HbqyqVcCNbR3gNGBV+1kHXAKDFwngPOB44DjgvMkXCknS4tiX6Z01wMa2vBE4c6j+qRq4BViW5NXAKcCmqtpdVY8Cm4BT9+H8kqQ5GjX0C/hykjuSrGu1I6vqIYD2+KpWXw48OLTvjlabrv4sSdYlmUgysWvXrtGvRJI0q1E/kfvWqtqZ5FXApiTfmqHtVJ9SqRnqzy5UbQA2AIyPj/sxR0maRyON9KtqZ3t8GPgSgzn577VpG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rqpbq+ojDH7t8NHA94FXzHDOQ4GH2ij1XTzzP4SZ9vsq8CvtnCcCj1TVQo0ih/sx3fPzHFX1twxePP47z4zyJwPykfZewLR368zSj71xA/CfJt9DmOWFfPj5/WkGUzgAP8Xghe3xJEcCp03uUFU7gZ3AhxlMVZHkCOBFVfUFBs/DW/ah/5oHjvT1LFW1K8l7gM8meUkrf7iq/ibJfwD+IskjwG3THOJ3kqxiMKq8Ebgb+C7PTCv8zyn2uRj4QpKzgJt4ZrS8BXgyyd0MQuSuoX3OB/64vTn6QwbTLAtlA/DnSR6qqrdN9fwwmB+fypXA7wArAarqsSR/yGDaZTtw+972Y+6XwceB3wW2tODfDvzCNG0v4ZnndzPtz7uq7k5yF4MppPsZTOcN+wyDef1vtvXl7TiTA8wP7UW/NY/83TsaWZKXV9UPWmD8AbC1qi5c6n5p/5HBXVx3VdWlS90XTc3pHc3Fr7fR+r0MpmT+9xL3R/uRJHcwmAb6k6Xui6bnSF8veEleyWCqaU8nV9XfLXZ/ZtPud1+5R/mDVXXDApzrFOCTe5QfqKp/O9/n0v7B0Jekjji9I0kdMfQlqSOGviR1xNCXpI78f0Jhr8R8aNwMAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data_all_test[data_all_test.registration_interval_time_days > 0.0].registration_interval_time_days.plot.box()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用 pd.cut() 方法进行散列化\n",
    "bins = [min(data_all_test.registration_interval_time_days)-1,30,180,365,365*2,365*3,365*4,365*5,365*6,365*7,365*8,max(data_all_test.registration_interval_time_days)+1]\n",
    "labels = [0,1,2,3,4,5,6,7,8,9,10]\n",
    "result = pd.cut(data_all_test.registration_interval_time_days, bins = bins, right = False, labels = labels)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test['reg_interval_days'] = result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test = data_all_test.drop(['registration_interval_time','registration_interval_time_days'], axis=1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['id', 'source_system_tab', 'source_screen_name', 'source_type', 'city', 'bd', 'gender', 'registered_via', 'song_length', 'language', 'reg_interval_days']\n"
     ]
    }
   ],
   "source": [
    "print(list(data_all_test.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>source_system_tab</th>\n",
       "      <th>source_screen_name</th>\n",
       "      <th>source_type</th>\n",
       "      <th>city</th>\n",
       "      <th>bd</th>\n",
       "      <th>gender</th>\n",
       "      <th>registered_via</th>\n",
       "      <th>song_length</th>\n",
       "      <th>language</th>\n",
       "      <th>reg_interval_days</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>0</td>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>1</td>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>2</td>\n",
       "      <td>discover</td>\n",
       "      <td>screen_name_NaN</td>\n",
       "      <td>song-based-playlist</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>3</td>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>52</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>4</td>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>-1</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        id source_system_tab   source_screen_name          source_type  city  \\\n",
       "76126    0        my library  Local playlist more        local-library     1   \n",
       "790668   1        my library  Local playlist more        local-library     1   \n",
       "52111    2          discover      screen_name_NaN  song-based-playlist     1   \n",
       "159296   3             radio                Radio                radio     3   \n",
       "160750   4             radio                Radio                radio     3   \n",
       "\n",
       "        bd      gender  registered_via  song_length language reg_interval_days  \n",
       "76126    1  gender_NaN               7            1        3                 3  \n",
       "790668   1  gender_NaN               7            2        3                 3  \n",
       "52111    1  gender_NaN               4            2       17                 0  \n",
       "159296   3        male               9            1       52                10  \n",
       "160750   3        male               9            1       -1                10  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_id_list = data_all_test.id\n",
    "with open(model_path + 'id_list_test.pkl','wb') as fw:\n",
    "    pk.dump(test_id_list,fw)\n",
    "fw.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test = data_all_test.drop(['id'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source_system_tab</th>\n",
       "      <th>source_screen_name</th>\n",
       "      <th>source_type</th>\n",
       "      <th>city</th>\n",
       "      <th>bd</th>\n",
       "      <th>gender</th>\n",
       "      <th>registered_via</th>\n",
       "      <th>song_length</th>\n",
       "      <th>language</th>\n",
       "      <th>reg_interval_days</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>discover</td>\n",
       "      <td>screen_name_NaN</td>\n",
       "      <td>song-based-playlist</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>52</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>-1</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       source_system_tab   source_screen_name          source_type  city  bd  \\\n",
       "76126         my library  Local playlist more        local-library     1   1   \n",
       "790668        my library  Local playlist more        local-library     1   1   \n",
       "52111           discover      screen_name_NaN  song-based-playlist     1   1   \n",
       "159296             radio                Radio                radio     3   3   \n",
       "160750             radio                Radio                radio     3   3   \n",
       "\n",
       "            gender  registered_via  song_length language reg_interval_days  \n",
       "76126   gender_NaN               7            1        3                 3  \n",
       "790668  gender_NaN               7            2        3                 3  \n",
       "52111   gender_NaN               4            2       17                 0  \n",
       "159296        male               9            1       52                10  \n",
       "160750        male               9            1       -1                10  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "for column in data_all_test.columns:\n",
    "    data_all_test[column] = data_all_test[column].astype('category')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将 所有字段都转换成了类别特征的特征数据 存储到硬盘\n",
    "with open(model_path + 'data_all_test_v2.pkl','wb') as fw:\n",
    "    pk.dump(data_all_test,fw)\n",
    "fw.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test_onehot = pd.get_dummies(data_all_test[list(data_all_test.columns)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 2556790 entries, 76126 to 86415\n",
      "Columns: 112 entries, source_system_tab_discover to reg_interval_days_10\n",
      "dtypes: uint8(112)\n",
      "memory usage: 332.6 MB\n"
     ]
    }
   ],
   "source": [
    "data_all_test_onehot.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source_system_tab_discover</th>\n",
       "      <th>source_system_tab_explore</th>\n",
       "      <th>source_system_tab_listen with</th>\n",
       "      <th>source_system_tab_my library</th>\n",
       "      <th>source_system_tab_notification</th>\n",
       "      <th>source_system_tab_radio</th>\n",
       "      <th>source_system_tab_search</th>\n",
       "      <th>source_system_tab_settings</th>\n",
       "      <th>source_system_tab_tab_NaN</th>\n",
       "      <th>source_screen_name_Album more</th>\n",
       "      <th>...</th>\n",
       "      <th>reg_interval_days_1</th>\n",
       "      <th>reg_interval_days_2</th>\n",
       "      <th>reg_interval_days_3</th>\n",
       "      <th>reg_interval_days_4</th>\n",
       "      <th>reg_interval_days_5</th>\n",
       "      <th>reg_interval_days_6</th>\n",
       "      <th>reg_interval_days_7</th>\n",
       "      <th>reg_interval_days_8</th>\n",
       "      <th>reg_interval_days_9</th>\n",
       "      <th>reg_interval_days_10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 112 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        source_system_tab_discover  source_system_tab_explore  \\\n",
       "76126                            0                          0   \n",
       "790668                           0                          0   \n",
       "52111                            1                          0   \n",
       "159296                           0                          0   \n",
       "160750                           0                          0   \n",
       "\n",
       "        source_system_tab_listen with  source_system_tab_my library  \\\n",
       "76126                               0                             1   \n",
       "790668                              0                             1   \n",
       "52111                               0                             0   \n",
       "159296                              0                             0   \n",
       "160750                              0                             0   \n",
       "\n",
       "        source_system_tab_notification  source_system_tab_radio  \\\n",
       "76126                                0                        0   \n",
       "790668                               0                        0   \n",
       "52111                                0                        0   \n",
       "159296                               0                        1   \n",
       "160750                               0                        1   \n",
       "\n",
       "        source_system_tab_search  source_system_tab_settings  \\\n",
       "76126                          0                           0   \n",
       "790668                         0                           0   \n",
       "52111                          0                           0   \n",
       "159296                         0                           0   \n",
       "160750                         0                           0   \n",
       "\n",
       "        source_system_tab_tab_NaN  source_screen_name_Album more  ...  \\\n",
       "76126                           0                              0  ...   \n",
       "790668                          0                              0  ...   \n",
       "52111                           0                              0  ...   \n",
       "159296                          0                              0  ...   \n",
       "160750                          0                              0  ...   \n",
       "\n",
       "        reg_interval_days_1  reg_interval_days_2  reg_interval_days_3  \\\n",
       "76126                     0                    0                    1   \n",
       "790668                    0                    0                    1   \n",
       "52111                     0                    0                    0   \n",
       "159296                    0                    0                    0   \n",
       "160750                    0                    0                    0   \n",
       "\n",
       "        reg_interval_days_4  reg_interval_days_5  reg_interval_days_6  \\\n",
       "76126                     0                    0                    0   \n",
       "790668                    0                    0                    0   \n",
       "52111                     0                    0                    0   \n",
       "159296                    0                    0                    0   \n",
       "160750                    0                    0                    0   \n",
       "\n",
       "        reg_interval_days_7  reg_interval_days_8  reg_interval_days_9  \\\n",
       "76126                     0                    0                    0   \n",
       "790668                    0                    0                    0   \n",
       "52111                     0                    0                    0   \n",
       "159296                    0                    0                    0   \n",
       "160750                    0                    0                    0   \n",
       "\n",
       "        reg_interval_days_10  \n",
       "76126                      0  \n",
       "790668                     0  \n",
       "52111                      0  \n",
       "159296                     1  \n",
       "160750                     1  \n",
       "\n",
       "[5 rows x 112 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test_onehot.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2556790, 112)"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test_onehot.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source_system_tab_discover</th>\n",
       "      <th>source_system_tab_explore</th>\n",
       "      <th>source_system_tab_listen with</th>\n",
       "      <th>source_system_tab_my library</th>\n",
       "      <th>source_system_tab_notification</th>\n",
       "      <th>source_system_tab_radio</th>\n",
       "      <th>source_system_tab_search</th>\n",
       "      <th>source_system_tab_settings</th>\n",
       "      <th>source_system_tab_tab_NaN</th>\n",
       "      <th>source_screen_name_Album more</th>\n",
       "      <th>...</th>\n",
       "      <th>reg_interval_days_1</th>\n",
       "      <th>reg_interval_days_2</th>\n",
       "      <th>reg_interval_days_3</th>\n",
       "      <th>reg_interval_days_4</th>\n",
       "      <th>reg_interval_days_5</th>\n",
       "      <th>reg_interval_days_6</th>\n",
       "      <th>reg_interval_days_7</th>\n",
       "      <th>reg_interval_days_8</th>\n",
       "      <th>reg_interval_days_9</th>\n",
       "      <th>reg_interval_days_10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 112 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        source_system_tab_discover  source_system_tab_explore  \\\n",
       "76126                            0                          0   \n",
       "790668                           0                          0   \n",
       "52111                            1                          0   \n",
       "159296                           0                          0   \n",
       "160750                           0                          0   \n",
       "\n",
       "        source_system_tab_listen with  source_system_tab_my library  \\\n",
       "76126                               0                             1   \n",
       "790668                              0                             1   \n",
       "52111                               0                             0   \n",
       "159296                              0                             0   \n",
       "160750                              0                             0   \n",
       "\n",
       "        source_system_tab_notification  source_system_tab_radio  \\\n",
       "76126                                0                        0   \n",
       "790668                               0                        0   \n",
       "52111                                0                        0   \n",
       "159296                               0                        1   \n",
       "160750                               0                        1   \n",
       "\n",
       "        source_system_tab_search  source_system_tab_settings  \\\n",
       "76126                          0                           0   \n",
       "790668                         0                           0   \n",
       "52111                          0                           0   \n",
       "159296                         0                           0   \n",
       "160750                         0                           0   \n",
       "\n",
       "        source_system_tab_tab_NaN  source_screen_name_Album more  ...  \\\n",
       "76126                           0                              0  ...   \n",
       "790668                          0                              0  ...   \n",
       "52111                           0                              0  ...   \n",
       "159296                          0                              0  ...   \n",
       "160750                          0                              0  ...   \n",
       "\n",
       "        reg_interval_days_1  reg_interval_days_2  reg_interval_days_3  \\\n",
       "76126                     0                    0                    1   \n",
       "790668                    0                    0                    1   \n",
       "52111                     0                    0                    0   \n",
       "159296                    0                    0                    0   \n",
       "160750                    0                    0                    0   \n",
       "\n",
       "        reg_interval_days_4  reg_interval_days_5  reg_interval_days_6  \\\n",
       "76126                     0                    0                    0   \n",
       "790668                    0                    0                    0   \n",
       "52111                     0                    0                    0   \n",
       "159296                    0                    0                    0   \n",
       "160750                    0                    0                    0   \n",
       "\n",
       "        reg_interval_days_7  reg_interval_days_8  reg_interval_days_9  \\\n",
       "76126                     0                    0                    0   \n",
       "790668                    0                    0                    0   \n",
       "52111                     0                    0                    0   \n",
       "159296                    0                    0                    0   \n",
       "160750                    0                    0                    0   \n",
       "\n",
       "        reg_interval_days_10  \n",
       "76126                      0  \n",
       "790668                     0  \n",
       "52111                      0  \n",
       "159296                     1  \n",
       "160750                     1  \n",
       "\n",
       "[5 rows x 112 columns]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test_onehot.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['source_system_tab_discover', 'source_system_tab_explore', 'source_system_tab_listen with', 'source_system_tab_my library', 'source_system_tab_notification', 'source_system_tab_radio', 'source_system_tab_search', 'source_system_tab_settings', 'source_system_tab_tab_NaN', 'source_screen_name_Album more', 'source_screen_name_Artist more', 'source_screen_name_Concert', 'source_screen_name_Discover Chart', 'source_screen_name_Discover Feature', 'source_screen_name_Discover Genre', 'source_screen_name_Discover New', 'source_screen_name_Explore', 'source_screen_name_Local playlist more', 'source_screen_name_My library', 'source_screen_name_My library_Search', 'source_screen_name_Online playlist more', 'source_screen_name_Others profile more', 'source_screen_name_Payment', 'source_screen_name_People global', 'source_screen_name_People local', 'source_screen_name_Radio', 'source_screen_name_Search', 'source_screen_name_Search Home', 'source_screen_name_Search Trends', 'source_screen_name_Self profile more', 'source_screen_name_Unknown', 'source_screen_name_screen_name_NaN', 'source_type_album', 'source_type_artist', 'source_type_listen-with', 'source_type_local-library', 'source_type_local-playlist', 'source_type_my-daily-playlist', 'source_type_online-playlist', 'source_type_radio', 'source_type_song', 'source_type_song-based-playlist', 'source_type_source_type_NaN', 'source_type_top-hits-for-artist', 'source_type_topic-article-playlist', 'city_1', 'city_3', 'city_4', 'city_5', 'city_6', 'city_7', 'city_8', 'city_9', 'city_10', 'city_11', 'city_12', 'city_13', 'city_14', 'city_15', 'city_16', 'city_17', 'city_18', 'city_19', 'city_20', 'city_21', 'city_22', 'bd_1', 'bd_2', 'bd_3', 'bd_4', 'bd_5', 'bd_6', 'bd_7', 'gender_female', 'gender_gender_NaN', 'gender_male', 'registered_via_3', 'registered_via_4', 'registered_via_7', 'registered_via_9', 'registered_via_13', 'registered_via_16', 'song_length_1', 'song_length_2', 'song_length_3', 'song_length_4', 'song_length_5', 'song_length_6', 'song_length_7', 'song_length_8', 'language_-1.0', 'language_3.0', 'language_10.0', 'language_17.0', 'language_24.0', 'language_31.0', 'language_38.0', 'language_45.0', 'language_52.0', 'language_59.0', 'language_language_NaN', 'reg_interval_days_0', 'reg_interval_days_1', 'reg_interval_days_2', 'reg_interval_days_3', 'reg_interval_days_4', 'reg_interval_days_5', 'reg_interval_days_6', 'reg_interval_days_7', 'reg_interval_days_8', 'reg_interval_days_9', 'reg_interval_days_10']\n"
     ]
    }
   ],
   "source": [
    "print(list(data_all_test_onehot.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_train_onehot_columns = ['source_system_tab_discover', 'source_system_tab_explore', 'source_system_tab_listen with', 'source_system_tab_my library', 'source_system_tab_notification', 'source_system_tab_radio', 'source_system_tab_search', 'source_system_tab_settings', 'source_system_tab_tab_NaN', 'source_screen_name_Album more', 'source_screen_name_Artist more', 'source_screen_name_Concert', 'source_screen_name_Discover Chart', 'source_screen_name_Discover Feature', 'source_screen_name_Discover Genre', 'source_screen_name_Discover New', 'source_screen_name_Explore', 'source_screen_name_Local playlist more', 'source_screen_name_My library', 'source_screen_name_My library_Search', 'source_screen_name_Online playlist more', 'source_screen_name_Others profile more', 'source_screen_name_Payment', 'source_screen_name_Radio', 'source_screen_name_Search', 'source_screen_name_Search Home', 'source_screen_name_Search Trends', 'source_screen_name_Self profile more', 'source_screen_name_Unknown', 'source_screen_name_screen_name_NaN', 'source_type_album', 'source_type_artist', 'source_type_listen-with', 'source_type_local-library', 'source_type_local-playlist', 'source_type_my-daily-playlist', 'source_type_online-playlist', 'source_type_radio', 'source_type_song', 'source_type_song-based-playlist', 'source_type_source_type_NaN', 'source_type_top-hits-for-artist', 'source_type_topic-article-playlist', 'city_1', 'city_3', 'city_4', 'city_5', 'city_6', 'city_7', 'city_8', 'city_9', 'city_10', 'city_11', 'city_12', 'city_13', 'city_14', 'city_15', 'city_16', 'city_17', 'city_18', 'city_19', 'city_20', 'city_21', 'city_22', 'bd_1', 'bd_2', 'bd_3', 'bd_4', 'bd_5', 'bd_6', 'bd_7', 'gender_female', 'gender_gender_NaN', 'gender_male', 'registered_via_3', 'registered_via_4', 'registered_via_7', 'registered_via_9', 'registered_via_13', 'song_length_1', 'song_length_2', 'song_length_3', 'song_length_4', 'song_length_5', 'song_length_6', 'song_length_7', 'song_length_8', 'language_-1.0', 'language_3.0', 'language_10.0', 'language_17.0', 'language_24.0', 'language_31.0', 'language_38.0', 'language_45.0', 'language_52.0', 'language_59.0', 'language_language_NaN', 'reg_interval_days_0', 'reg_interval_days_1', 'reg_interval_days_2', 'reg_interval_days_3', 'reg_interval_days_4', 'reg_interval_days_5', 'reg_interval_days_6', 'reg_interval_days_7', 'reg_interval_days_8', 'reg_interval_days_9', 'reg_interval_days_10']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test_onehot_columns = list(data_all_test_onehot.columns)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 所有的字段以训练集为准，测试集多的就删除，少的就添加为0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 训练集中有的特征测试集没有\n",
    "for item in data_all_train_onehot_columns:\n",
    "    if item not in data_all_test_onehot_columns:\n",
    "        print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "source_screen_name_People global\n",
      "source_screen_name_People local\n",
      "registered_via_16\n"
     ]
    }
   ],
   "source": [
    "# 测试集中有的特征训练集没有\n",
    "for item in data_all_test_onehot_columns:\n",
    "    if item not in data_all_train_onehot_columns:\n",
    "        print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2556790"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_all_test_onehot.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_all_test_onehot=data_all_test_onehot.drop(['source_screen_name_People global','source_screen_name_People local','registered_via_16'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "============\n"
     ]
    }
   ],
   "source": [
    "# 训练集中有的特征测试集没有\n",
    "for item in data_all_train_onehot_columns:\n",
    "    if item not in data_all_test_onehot_columns:\n",
    "        print(item)\n",
    "print('============')\n",
    "# 测试集中有的特征训练集没有\n",
    "for item in data_all_test_onehot.columns:\n",
    "    if item not in data_all_train_onehot_columns:\n",
    "        print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将 类别特征onehot后 存储到硬盘\n",
    "# ['source_system_tab', 'source_screen_name', 'source_type', 'city', 'bd', 'gender', 'registered_via', 'song_length', 'language', 'reg_interval_days']\n",
    "with open(model_path + 'data_all_test_onehot.pkl','wb') as fw:\n",
    "    pk.dump(data_all_test_onehot,fw)\n",
    "fw.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
